// 团购
function Timer() {
    $(".tuan-remains").each(function () {

        var counter = $(this);
        var b = (new Date()).getTime();
        var self = $(this).siblings('.time_left').val();
        var buybtn = $(this).parents("DL").find(".tuan-buyit");
        var e = function () {
            var c = (new Date()).getTime();
            var a = parseInt(self) * 1000;
            var ls = a + b - c;

            if (ls > 0) {
                var ld = parseInt(ls / 86400000).toString();
                ld = ld.length > 1 ? ld : '0' + ld;
                ls = ls % 86400000;
                var lh = parseInt(ls / 3600000).toString();
                lh = lh.length > 1 ? lh : '0' + lh;
                ls = ls % 3600000;

                var lm = parseInt(ls / 60000).toString();
                lm = lm.length > 1 ? lm : '0' + lm;

                var lms = parseInt((ls % 60000) / 100);
                ls = parseInt(lms / 10);
                var tms = lms - ls * 10;

                ls = ls.toString().length > 1 ? ls : '0' + ls;

                var html = '<span class="z">' + ld + '</span>:<span class="z">' + lh + '</span>:<span class="z">' + lm + '</span>:<span class="z">' + ls + '.' + tms + '</span>';


                counter.html(html);
            }
            else {
                counter.stopTime('timer');
                counter.html('已结束');
                buybtn.removeClass("tuan-buyit").addClass("tuan-end-buyit").text("已结束");
            }
        };
        counter.everyTime(100, 'timer', e);
    });
}

$(function () {

    // 定时器end

    // 排序
    $(".order LI").click(function () {
        var c = 'order-current';
        if ($(this).is("." + c)) {
            var t = $(this).find('.triangle');
            var r = t.text() == '▼' ? '▲' : '▼';
            t.text(r);
        }
        else {
            $(this).addClass(c).siblings("." + c).removeClass(c);
        }
    });
    /*切换*/
    $(".info-tab LI").each(function (index) {
        $(this).click(function () {
            $(this).addClass("info-cur").siblings("LI").removeClass("info-cur");
            $(".details-info").eq(index).show().siblings(".details-info").hide();
        });
    });
    /*切换end*/


});
// 团购 天天惠 end
// 购物车

// 订单确认
$(function () {

    // 发票弹框
    $(".receipt-cfm").click(function () {
        showFullBox($('.receipt-cfm-box'));
    });
    // 发票弹框end

    // 发票选择
    $(".receipt-cfm-box DL").click(function () {
        showFullBox($('.receipt-cfm-box'), 1);
    });
    // 发票选择end
    // 优惠券弹框
    //$(".ticket-cfm").click(function () {

    //    showFullBox($('.ticket-cfm-box'));
    //});
    //// 优惠券弹框end
    //// 优惠券选择
    //$(".ticket-cfm-box DL").click(function () {
    //    showFullBox($('.ticket-cfm-box'), 1);
    //});
    // 优惠券选择end

    // 地址弹框
    $(".cfm-addr-bar").click(function () {
        window.onscroll = function (e) {
            e.preventDefault();
        }
        var addresslist = $("#address-list");
        addresslist.empty();
        $.get("http://m.caichongwang.com/js/makerorder.aspx?act=address", function (data) {
            for (var i in data) {
                var item = data[i];
                var dom = '<dl data-name="' + item["Name"] + '" data-phone="' + item["Phone"] + '" data-address="' + item["Address"] + '" data-addressid="' + item["AddressId"] + '">'
                + '<dt>收货人：' + item["Name"] + '(' + item["Phone"] + ')</dt>'
                + '<dd>收货地址：' + item["Address"] + '</dd></dl>';
                addresslist.append(dom);
            }
            showFullBox($('.addr-cfm-box'));
            $(".addr-cfm-box DL").click(dlClick);
        });


    });
    $("#new-address").click(function () {
        var name = $("#new-addr-name").val(), sltStateProvince = $("#sltStateProvince").val(), sltCity = $("#sltCity").val(),
            sltCityArea = $("#sltCityArea").val(), address = $("#new-addr-address").val(), phone = $("#new-addr-phone").val();

        $.post("http://m.caichongwang.com/js/addresslist.aspx", { "addr-name": name, sltStateProvince: sltStateProvince, sltCity: sltCity, sltCityArea: sltCityArea, "addr-detail": address, json: "1", createoredit: 1, "addr-phone": phone }, function (result) {
            if (result.Msg === 'Ok') {
                var item = result.Obj;
                var dom = '<dl data-name="' + item["name"] + '" data-phone="' + item["phone"] + '" data-address="' + item["address"] + '" data-addressid="' + item["addressid"] + '">'
        + '<dt>收货人：' + item["name"] + '(' + item["phone"] + ')</dt>'
        + '<dd>收货地址：' + item["address"] + '</dd></dl>';

                $("#address-list").append(dom);
                $(".addr-cfm-box DL").click(dlClick);
            }

        });
    });
    var dlClick = function () {
        var name = $(this).data("name"), phone = $(this).data("phone"), address = $(this).data("address"),
            addressid = $(this).data("addressid");

        $(".addr-name").empty().html(name + "(" + phone + ")");
        $(".addr-details").empty().html(address);

        $("#addr-name").val(name);
        $("#addr-address").val(address);
        $("#addr-addressid").val(addressid);
        showFullBox($('.addr-cfm-box'), 1);
    }
    // 地址弹框end
    // 地址选择

    // 地址选择end
    // 贺卡呈现
    $("#postcard,#cupon").click(function () {
        if ($(this).is(":checked")) {
            $(".postcard-cont", $(this).parents("section")).show();
        }
        else {
            $(".postcard-cont", $(this).parents("section")).hide();
        }
    });
    // 贺卡呈现end
    // 提交判断
    // 预付款密码
    $("#gotopay").click(function () {
        if (!$(".prepay").is(":hidden") && !$(".prepay INPUT").val().length) {
            warnpop("请输入预付款密码");
            showFullBox($(".warnbox"));
            return false;
        }
        if (!$("#agree-prepay").is(":hidden")) {
            warnpop("请同意支付订金");
            showFullBox($(".warnbox"));
            return false;
        }
    });
    $(".warn-btn A").click(function () {
        showFullBox($(".warnbox"), 1);
    });
    // 预付款密码end
    // 发票信息
    $("#new-receipt , #new-address , #new-ticket").click(function () {
        $(this).attr("href", "javascript:void(0)");
        var input = $(this).parents("P").siblings("P").find("INPUT[type='text']");
        input.each(function () {
            if (!$(this).val().length) {
                var t = $(this);
                var i = 0;
                var warnmsg = setInterval(function () {
                    if (i > 12) {
                        clearInterval(warnmsg);
                    }
                    t.parent("P").toggleClass("warn-input");
                    i++;
                }, 400)
                $(this).focus();
                return false;
            }
        })
    });
    // 发票信息end
    // 提交判断end



});

// 订单确认end
